package com.hctforgreen.greenservice.model;

import org.json.JSONException;
import org.json.JSONObject;
/**
 * 版本控制
 * @author Tallen Zhai
 *
 */
public class VersionCodeEntity extends BaseEntity {

	private static final long serialVersionUID = -1229959364723349933L;
	public String state = "";
	public BodyEntity bodyEntity = null;
	
	public final static String STATE = "state";
	private final static String BODY = "body";
	public static VersionCodeEntity parse(JSONObject jsonObject)throws JSONException{
		VersionCodeEntity bean = new VersionCodeEntity();
		if(jsonObject.has(STATE)){
			bean.state = jsonObject.getString(STATE);
		}
		/**
		 * 解析body节点
		 */
		if (jsonObject.has(BODY)) {
			JSONObject bodyObject = jsonObject.getJSONObject(BODY);
			bean.bodyEntity = BodyEntity.parse(bodyObject);
		}
		if(bean.bodyEntity == null){
			bean.bodyEntity = new BodyEntity();
		}
		return bean;
	}
	public static class BodyEntity extends BaseEntity {

		private static final long serialVersionUID = -5277269118034272059L;
		/**
		 * 当前版本号
		 */
		public String code = "";
		/**
		 * 版本号状态 0--正常使用，1--强制更新
		 */
		public String state = "";
		/**
		 * 最高版本
		 */
		public String hcode = "";
		/**
		 * 更新说明
		 */
		public String explain = "";
		/**
		 * 下载路径 
		 */
		public String url = "";
		public final static String CODE = "code";
		public final static String STATE = "state";
		public final static String H_CODE = "hcode";
		public final static String EXPLAIN = "explain";
		public final static String URL = "url";
		public static BodyEntity parse(JSONObject jsonObject)
				throws JSONException {
			BodyEntity bean = new BodyEntity();
			if (jsonObject.has(CODE)) {
				bean.code = jsonObject.getString(CODE);
			}
			if (jsonObject.has(STATE)) {
				bean.state = jsonObject.getString(STATE);
			}
			if (jsonObject.has(H_CODE)) {
				bean.hcode = jsonObject.getString(H_CODE);
			}
			if (jsonObject.has(EXPLAIN)) {
				bean.explain = jsonObject.getString(EXPLAIN);
			}
			if (jsonObject.has(URL)) {
				bean.url = jsonObject.getString(URL);
			}
			return bean;
		}
	}
}
